home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: redoSetRootEntry.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:57 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "logrecs.h"
- #include "trans.h"
- #include "openlog.h"
- #include "io_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "util_funcs.h"
- #include "trans_extfuncs.h"
- #include "redo_extfuncs.h"
- #include "redo_intfuncs.h"
- #include "thread_globals.h"
- #include "log_globals.h"
- #include "log_extfuncs.h"
-
-
- void
- redoSetRootEntry (
-
- LOGRECORDHDR *record
- )
- {
-
- register ROOTENTRY *current;
- register ROOTENTRY *end;
- register VOLREC *volRec;
- register GROUPLINK *rootLink;
- register DIRTYPAGEINFO *dirtyInfo;
- char *newData;
- FOUR newDataSize;
- ROOTPAGE *rootPage;
- PID pid;
- VOLID volid;
- ROOTENTRYLOGINFO *entryInfo;
-
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN));
-
- /*
- * get a pointer to the name in the record
- */
- volid = record->actionPid.volid;
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("volid:%d", volid));
-
- /*
- * construct the pid
- */
- pid.volid = volid;
- pid.page = ROOTPAGEADDR;
- SM_ASSERT(LEVEL_3, ROOTPAGEADDR == record->actionPid.page);
-
- /*
- * check to see if the page is in the dirty page list
- */
- if ((dirtyInfo = searchDirtyPageTable(&pid)) == NULL) {
-
- /*
- * don't need to redo
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
- return;
- }
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record.
- * Also check the lsn for the case of pages which never made it
- * back from the client.
- */
- if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
-
- /*
- * don't need to redo
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
- return;
- }
-
- /* get a pointer to information about the entry */
- entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(record, 0);
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name:%s", entryInfo->name));
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
-
- /*
- * get a pointer to the new data and size in the record
- */
- newData = GET_LOG_IMAGE(record, 2);
- newDataSize = GET_LOG_IMAGE_SIZE(record, 2);
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("new data:%s", newData));
-
- if ((volRec = io_FindVolRec(volid)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * read in the root page
- */
- if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the root page
- */
- rootPage = (ROOTPAGE *) rootLink->bufFrame;
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record
- */
- if (compareLRC( &(record->actionLRC), &(rootPage->lrc)) <= 0) {
-
- /*
- * don't need to redo
- * mark the page lsn
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
- dirtyInfo->lrc = rootPage->lrc;
-
- /*
- * release the page
- */
- signalSemaphore( &(rootLink->pageHash->semaphore) );
- bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
- return;
- }
-
- /*
- * Initialize the search variables
- */
- current = &(rootPage->entry[0]);
- end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
-
- /*
- * See if the root entry was originally allocated in a free
- * entry slot.
- */
- if (entryInfo->oldFlags == ROOT_FREE) {
-
- /*
- * look for a free spot
- */
- while (current < end) {
-
- /*
- * check to see if the slot is free
- */
- if (current->flags == ROOT_FREE) {
-
- /*
- * free the information
- */
- current->flags = ROOT_USED;
-
- /*
- * plug in the information
- */
- strncpy(current->name, (char *)entryInfo->name, MAX_ROOTNAME_SIZE);
- bcopy(newData, current->data, (int)newDataSize);
- current->dataSize = newDataSize;
-
- /*
- * mark the lsn
- * Set up the firstLSN/LRC for the page
- */
- rootPage->lrc = record->actionLRC;
- DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
- rootPage->lrc.count));
-
- /*
- * signal the semaphore and unfix the page
- */
- signalSemaphore( &(rootLink->pageHash->semaphore) );
- bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
-
- return;
- }
-
- /*
- * look at the next entry
- */
- current++;
- }
-
- /*
- * There should be a free entry since history is being
- * redone. So, return an error.
- */
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("no match"));
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
-
- } else {
-
- /*
- * This entry already existed, but the set operation
- * changed the data, so search for the entry and
- * change the data.
- */
- while (current < end) {
-
- /*
- * check to see if the slot is free
- */
- if (current->flags != ROOT_FREE) {
-
- /*
- * check to see if the name matches
- */
- if (!strcmp(current->name, (char *)entryInfo->name)) {
-
- TRPRINT(TR_IO, TR_LEVEL_2, ("found name at slot:%d", current->index));
- /*
- * plug in the information
- */
- bcopy(newData, current->data, (int)newDataSize);
- current->dataSize = newDataSize;
-
- /*
- * mark the lsn
- * Set up the firstLSN/LRC for the page
- */
- rootPage->lrc = record->actionLRC;
- DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
- rootPage->lrc.count));
-
- /*
- * signal the semaphore, unfix the page and return
- */
- signalSemaphore( &(rootLink->pageHash->semaphore) );
- bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
- return;
- }
- }
-
- /*
- * look at the next entry
- */
- current++;
- }
-
- /*
- * There should be a matching entry since history is being
- * redone. So, return an error.
- */
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name not found"));
- SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
-
- }
-
- /*
- * This statement should not be reached
- */
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
-
-
-
- void
- redoRemoveRootEntry (
-
- LOGRECORDHDR *record
- )
- {
-
- ROOTENTRY *current;
- ROOTENTRY *end;
- VOLREC *volRec;
- GROUPLINK *rootLink;
- DIRTYPAGEINFO *dirtyInfo;
- ROOTPAGE *rootPage;
- PID pid;
- VOLID volid;
- ROOTENTRYLOGINFO *entryInfo;
-
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN));
-
- /* get a pointer to the name in the record */
- volid = record->actionPid.volid;
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("volid:%d", volid));
-
- /* construct the pid */
- pid.volid = volid;
- pid.page = ROOTPAGEADDR;
- SM_ASSERT(LEVEL_3, ROOTPAGEADDR == record->actionPid.page);
-
- /* check to see if the page is in the dirty page list */
- if ((dirtyInfo = searchDirtyPageTable(&pid)) == NULL) {
-
- /* don't need to redo */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
- return;
- }
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record.
- * Also check the lsn for the case of pages which never made it
- * back from the client.
- */
- if ( (compareLRC(&(record->actionLRC), &(dirtyInfo->lrc)) < 0) ||
- (compareLSN(&(record->recordLSN), &(dirtyInfo->lsn)) < 0) ) {
-
- /* don't need to redo */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
- return;
- }
-
- /*
- * Make sure the comparison was correct
- */
- SM_ASSERT(LEVEL_3, compareLSN( &(record->recordLSN), &(dirtyInfo->lsn)) >= 0);
-
- /* get a pointer to information about the entry */
- entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(record, 0);
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name:%s", entryInfo->name));
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
-
- if ((volRec = io_FindVolRec(volid)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * read in the root page
- */
- if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the root page
- */
- rootPage = (ROOTPAGE *) rootLink->bufFrame;
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record
- */
- if (compareLRC( &(record->actionLRC), &(rootPage->lrc)) <= 0) {
-
- /*
- * don't need to redo
- * mark the page lsn
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
- dirtyInfo->lrc = rootPage->lrc;
-
- /* release the page */
- signalSemaphore( &(rootLink->pageHash->semaphore) );
- bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
- return;
- }
-
- /*
- * Initialize the search variables
- */
- current = &(rootPage->entry[0]);
- end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
-
- /*
- * This entry already existed, but the set operation
- * changed the data, so search for the entry and
- * change the data.
- */
- while (current < end) {
-
- /*
- * check to see if the slot is free
- */
- if (current->flags != ROOT_FREE) {
-
- /*
- * check to see if the name matches
- */
- if (!strcmp(current->name, (char *)entryInfo->name)) {
-
- TRPRINT(TR_IO, TR_LEVEL_2, ("found name at slot:%d", current->index));
-
- /* mark the entry free */
- current->flags = ROOT_FREE;
-
- /*
- * mark the lsn
- * Set up the firstLSN/LRC for the page
- */
- rootPage->lrc = record->actionLRC;
- DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
- rootPage->lrc.count));
-
- /*
- * signal the semaphore, unfix the page and return
- */
- signalSemaphore( &(rootLink->pageHash->semaphore) );
- bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
- return;
- }
- }
-
- /*
- * look at the next entry
- */
- current++;
- }
-
- /*
- * There should be a matching entry since history is being
- * redone. So, return an error.
- */
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name not found"));
- SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
-
- /*
- * This statement should not be reached
- */
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-